//
//  OrderBodyCell.m
//  PigMarket
//
//  Created by 张敬 on 2019/8/13.
//  Copyright © 2019年 pigmarket.oc. All rights reserved.
//

#import "OrderBodyCell.h"

@interface OrderBodyCell ()

/**
 店铺Icon
 */
@property (nonatomic, strong) UIImageView *shopIcon; //店铺Icon


/**
 猪类型
 */
@property (nonatomic, strong) UILabel *pigTypeTipLab;


/**
 猪编号
 */
@property (nonatomic, strong) UILabel *pigTypeNOLab;


/**
 猪价格
 */
@property (nonatomic, strong) UILabel *pigTypePriceLab;


/**
 猪重量
 */
@property (nonatomic, strong) UILabel *pigTypeWeightLab;


/**
 猪单价
 */
@property (nonatomic, strong) UILabel *pigTypePriceSignalLab;


/**
 寄宿View
 */
@property (nonatomic, strong) UIView *view;


@end


@implementation OrderBodyCell

- (void)setupUI
{
    [self addSubview:self.shopIcon];
    [self addSubview:self.pigTypeTipLab];
    [self addSubview:self.pigTypeNOLab];
    [self addSubview:self.pigTypePriceLab];
    [self addSubview:self.pigTypeWeightLab];
    [self addSubview:self.pigTypePriceSignalLab];
    
}


- (void)setupLayout
{
    {
        _shopIcon.size = CGSizeMake(56, 56);
        _shopIcon.mj_x = 15;
        _shopIcon.mj_y = 10;
    }
    
    
    {
        _pigTypeTipLab.frame = CGRectMake(0, 0, 200, 30);
        [_pigTypeTipLab sizeToFit];
        _pigTypeTipLab.width += 10;
        _pigTypeTipLab.height += 5;
        _pigTypeTipLab.mj_x = _shopIcon.right + 10;
        _pigTypeTipLab.mj_y = 12;
    }
    
    
    {
        _pigTypeNOLab.size = CGSizeMake(100, 21);
        _pigTypeNOLab.mj_x = _pigTypeTipLab.right + 5;
        _pigTypeNOLab.mj_y = _pigTypeTipLab.mj_y;
    }
    
    
    {
        _pigTypeWeightLab.frame = CGRectMake(0, 0, 200, 30);
        [_pigTypeWeightLab sizeToFit];
        _pigTypeWeightLab.width += 10;
        _pigTypeWeightLab.height += 5;
        _pigTypeWeightLab.mj_x = _shopIcon.right + 10;
        _pigTypeWeightLab.mj_y = _pigTypeTipLab.bottom + 5;
    }
    
    
    {
        _pigTypePriceSignalLab.frame = CGRectMake(0, 0, 200, 30);
        [_pigTypePriceSignalLab sizeToFit];
        _pigTypePriceSignalLab.width += 10;
        _pigTypePriceSignalLab.height += 5;
        _pigTypePriceSignalLab.mj_x = _pigTypeWeightLab.right + 5;
        _pigTypePriceSignalLab.mj_y = _pigTypeWeightLab.mj_y;
    }
    
    {
        _pigTypePriceLab.size = CGSizeMake(100, 17);
        _pigTypePriceLab.mj_x = KScreenWidth - _pigTypePriceLab.width - 45;
        _pigTypePriceLab.mj_y = (64 - _pigTypePriceLab.height)/2.0;
    }
}

#pragma mark - setter methods

- (void)setItem:(MeatOrderDetailsModel *)item{
    
    [_shopIcon sd_setImageWithURL:[NSURL URLWithString:item.meatHeadImg] placeholderImage:[UIImage imageNamed:@"placeholder_small"]];
    
    _pigTypeTipLab.text = item.aliasName;
    _pigTypeNOLab.text = item.chunksName;
    _pigTypeWeightLab.text = [NSString stringWithFormat:@"重量%@kg", item.weight];
    _pigTypePriceSignalLab.text = [NSString stringWithFormat:@"单价%@元/500g",item.unitPrice];
    _pigTypePriceLab.text = [NSString stringWithFormat:@"¥%@", item.payPrice];

    [self setupLayout];
}

- (void)setDetailItem:(MeatOrderDetailItemModel *)detailItem{
    
    
    [_shopIcon sd_setImageWithURL:[NSURL URLWithString:detailItem.meatHeadImg] placeholderImage:[UIImage imageNamed:@"placeholder_small"]];
    
    _pigTypeTipLab.text = detailItem.aliasName;
    _pigTypeNOLab.text = detailItem.chunksName;
    _pigTypeWeightLab.text = [NSString stringWithFormat:@"重量%@kg", detailItem.weight];
    _pigTypePriceSignalLab.text = [NSString stringWithFormat:@"单价%@元/500g",detailItem.unitPrice];
    _pigTypePriceLab.text = [NSString stringWithFormat:@"¥%@", detailItem.payPrice];
    
    [self setupLayout];

    
}


#pragma mark - getter methods

- (UIImageView *)shopIcon{
    if (!_shopIcon) {
        _shopIcon = [[UIImageView alloc] init];
        [self addShadowAndCircleCorner:_shopIcon.layer corner:5];
        _shopIcon.image = [UIImage imageNamed:@"placeholder_small"];
    }
    return _shopIcon;
}


- (UILabel *)pigTypeTipLab{
    
    if (! _pigTypeTipLab){
        _pigTypeTipLab = [UILabel makeLabelWithText:@"" textColor:mMainColor font:mFont(12) textAliment:1];
        _pigTypeTipLab.backgroundColor = UIColorFromRGB(0xE9F9F0);
        [self addShadowAndCircleCorner:_pigTypeTipLab.layer corner:3];
    }
    return _pigTypeTipLab;
}


- (UILabel *)pigTypeNOLab{
    
    if (!_pigTypeNOLab){
        _pigTypeNOLab = [UILabel makeLabelWithText:@"" textColor:UIColorFromRGB(0x333333) font:mFont(15) textAliment:0];
    }
    return _pigTypeNOLab;
}


- (UILabel *)pigTypePriceLab{
    
    if (!_pigTypePriceLab){
        _pigTypePriceLab = [UILabel makeLabelWithText:@"" textColor:UIColorFromRGB(0x4D4D4D) font:mFont(12) textAliment:2];
    }
    return _pigTypePriceLab;
}


- (UILabel *)pigTypeWeightLab {
    
    if (!_pigTypeWeightLab){
        _pigTypeWeightLab = [UILabel makeLabelWithText:@"" textColor:UIColorFromRGB(0x9C9C9C) font:mFont(10) textAliment:1];
        _pigTypeWeightLab.backgroundColor = UIColorFromRGB(0xF2F4F7);
        [self addShadowAndCircleCorner:_pigTypeWeightLab.layer corner:9];
    }
    return _pigTypeWeightLab;
}


- (UILabel *)pigTypePriceSignalLab{
    
    if (!_pigTypePriceSignalLab){
        _pigTypePriceSignalLab = [UILabel makeLabelWithText:@"" textColor:UIColorFromRGB(0x9C9C9C) font:mFont(10) textAliment:1];
        _pigTypePriceSignalLab.backgroundColor = UIColorFromRGB(0xF2F4F7);
        [self addShadowAndCircleCorner:_pigTypePriceSignalLab.layer corner:9];
    }
    return _pigTypePriceSignalLab;
}


@end
